﻿// JScript 文件

 	var hideDiv = function(idName){
 		$("#"+idName).fadeOut("fast");
 	};
 	
 	//是否显示上传后的图片
 	var isshowpic = true;  
 	var uploadshowpic = function(el){
 	    isshowpic = !(isshowpic);
 	    if(isshowpic)
 	    {
 	        el.html("图片显示关闭");
 	    }
 	    else
 	    {
 	        el.html("图片显示开启");
 	    }
 	};
 	
 	//载入中的GIF动画
    var loadingUrl = "../_imgs/loading.gif";
    
    //选择文件后的事件,iframe里面调用的
    var uploading = function(imgsrc,itemid){
        var el = $("#uploading"+itemid);
        $("#ifUpload"+itemid).fadeOut("fast");
        el.fadeIn("fast");
	    el.html("<img src='"+loadingUrl+"' align='absmiddle' /> 上传中...");
	    return el;
    };
    
    //上传时程序发生错误时，给提示，并返回上传状态
    var uploaderror = function(errMsg){
        alert(errMsg);
        uploadinit();
    };
    
    //上传成功后的处理
	var uploadsuccess = function(newpath,itemid,realname,filename,name,filetype){
	    var oldvalue="";
	    switch(itemid)
	    {
	        case "1":
                $("#uploading"+itemid).fadeOut("fast");
                $("#ifUpload"+itemid).fadeIn("fast");
                oldvalue=$("#uploadVa_"+itemid).val();
                $("#uploadVa_"+itemid).addfile(filename);
	            break;
	        case "2":
                $("#uploading"+itemid).fadeOut("fast");
                $("#divUploadPic").fadeOut("fast");
                $("#uploadVa_"+itemid).val(filename);
	            break;
	    }
        if(isshowpic)
        {
            $("#divFilesList"+itemid).append("<div class=\"attachmentitems\">"+filetype+"&nbsp;&nbsp;<a href='"+newpath+"' title='点击打开文件' target='_blank'>"+name+"</a>&nbsp;&nbsp; <a href='javascript:void(0);' realname='"+realname+"' filename='"+filename+"' itemid='"+itemid+"' onclick='uploadinit($(this));'>[删除]</a></div>");        
            $("#divFilesList"+itemid).fadeIn("fast");
        }
    };
    
    
    var currentItemID = 0;  //用于存放共有多少个上传控件了
    //创建一个上传控件
    var uploadcreate = function(el,itemid){
        currentItemID ++;
        if(itemid == null)
        {
            itemid = currentItemID;
        }  
        var strContent = "<div><iframe src=\"../fileupload.aspx?id="+itemid+"\" id=\"ifUpload"+itemid+"\" frameborder=\"no\" scrolling=\"no\" style=\"width:100%;height:30px;margin:0px;padding:0px;\"></iframe>";
	    strContent += "<div id=\"uploading"+itemid+"\" style=\"display:none;\" ></div>";
	    strContent += "<div id=\"panelViewPic"+itemid+"\" style=\"display:none;\"></div></div>";
	    el.append(strContent);
    };
    var uploadformaterror=function(msg,itemid){
        alert(msg);
        $("#ifUpload2").fadeIn("fast");
        $("#divUploadPic").fadeIn("fast");
        $("#divFilesList2").fadeOut("fast");
        $("#uploading2").hide("fast");
        $("#uploadVa_2").val('');
    }
    
$.fn.extend({ 
        removefile:function(data){
                var _fileValue=$(this).val().replace("|"+data,"");
                $(this).val(_fileValue);
        },
        addfile:function(data){
                var _fileValue=$(this).val()+"|"+data;
                $(this).val(_fileValue);
        }
})